﻿Imports System.Text
Public Class JapanForm

    Private Sub btnC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnC.Click
        Me.Close()
    End Sub
    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        
        If (Not (DoCheck())) Then
            Exit Sub
        End If

        Dim cv As New CrystlViewer
        cv._ParamsValues.Add("TITLE", "日语报表")
        cv._Rt = CrystlViewer.ReportType.Japanese

        cv._ParamsValues.Add("dtStartTime", Me.dtStartTime.Text.ToString())
        cv._ParamsValues.Add("dtEndTime", Me.dtEndTime.Text.ToString())

        Me.Opacity = 0
        Me.Visible = False
        Dim pf As New ProgessForm(cv)
        pf.ShowDialog()
        Me.Close()
   
    End Sub

#Region "创建数据源"
    Private Function CreateDataSource(ByRef ds As DataSet) As Boolean
        CreateDataSource = Nothing
        '声明适配器
        Dim oa As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter()
        '声明表当数据源
        Dim dt As New DataTable("DsJapanWord_XSCWORD")
        '连接查询数据
        Dim sb As New StringBuilder

        sb.AppendLine(" SELECT ")
        sb.AppendLine(" JAPANWORD ")
        If (chkJAPANPLANT.Checked) Then
            sb.AppendLine(" ,JAPANPLANT ")
        End If
        If (Me.chkCHINESEPLANT.Checked) Then
            sb.AppendLine(" ,CHINESEPLANT ")
        End If
        If (Me.chkJAPANJUZHI.Checked) Then
            sb.AppendLine(" ,JAPANJUZHI ")
        End If
        sb.AppendLine(" ,CHINESEPLANT ")
        sb.AppendLine(" ,JAPANJUZHI ")
        sb.AppendLine(" ,date([ADDTIME]) as ADDTIME ")
        sb.AppendLine(" from XSCWORD ")
        sb.AppendLine(" WHERE 1=1 ")
        Dim dbtype As Integer = 0
        dbtype = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings("dbtype"))
        If dbtype = 1 Then
            ' rs = ct.GetTable("select * from XSCFEEL WHERE DATE=#" + ID + "#  and USERNAME='" + Me.strName + "'")
            sb.AppendLine(" AND ADDTIME>=#" + Me.dtStartTime.Value.ToString + "#")
            sb.AppendLine(" AND ADDTIME<=#" + Me.dtEndTime.Value.ToString + "#")
        ElseIf dbtype = 2 Then
            ' rs = ct.GetTable("select * from XSCFEEL WHERE DATE='" + ID + "'  and USERNAME='" + Me.strName + "'")
            sb.AppendLine(" AND ADDTIME>='" + Me.dtStartTime.Value.ToString + "'")
            sb.AppendLine(" AND ADDTIME<='" + Me.dtEndTime.Value.ToString + "'")
        ElseIf dbtype = 3 Then
            ' rs = ct.GetTable("select * from XSCFEEL WHERE date([DATE])='" + DateTime.Parse(ID).ToString("yyyy-MM-dd") + "'     and USERNAME='" + Me.strName + "'")
            sb.AppendLine(" AND date([ADDTIME])>='" + Me.dtStartTime.Value.ToString("yyyy-MM-dd") + "'")
            sb.AppendLine(" AND date([ADDTIME])<='" + Me.dtEndTime.Value.ToString("yyyy-MM-dd") + "'")
        End If
        Dim rs As ADODB.Recordset = ct.GetTable(sb.ToString())
        '填充表
        oa.Fill(dt, rs)
        If dt Is Nothing Then
            ShowMessageBox("数据库错误")
            Return False
        End If

        If dt.Rows.Count = 0 Then
            ShowMessageBox("没有数据")
            Return False
        End If
        rs.Close()
        rs = Nothing

        '添加到DS中
        ds.Tables.Add(dt)
        '设置表名不能缺少
        ds.Tables.Item(0).TableName = "XSCWORD"
        Return True
    End Function
#End Region

#Region "画面的CHECK A-2009-09-11"
    Public Function DoCheck() As Boolean
        'A-2009-09-11 
        Dim strTimeStart As String = ""
        Dim strTimeEnd As String = ""
        strTimeStart = String.Format("{0:00}{1:00}{2:00}", dtStartTime.Value.Year, dtStartTime.Value.Month, dtStartTime.Value.Day)
        strTimeEnd = String.Format("{0:00}{1:00}{2:00}", dtEndTime.Value.Year, dtEndTime.Value.Month, dtEndTime.Value.Day)
        'A-2009-09-11

        'D-2009-09-11
        'If dtStartTime.Value > dtEndTime.Value Then
        '    ShowMessageBox("开始时间不能大于结束时间")
        '    Return False
        'End If
        'D-2009-09-11

        'A-2009-09-11
        If strTimeStart > strTimeEnd Then
            ShowMessageBox("开始时间不能大于结束时间")
            Return False
        End If
        'A-2009-09-11

        Return True
    End Function
#End Region

End Class
